set -eux

work_path=$(pwd)

config_start() {
  nohup sudo /usr/local/bin/x-set-keys \
     --exclude-focus-class=Gnome-terminal \
     /home/axe/guaconfig/keymap/keymap-v2.conf &

}

config_keymap() {
    if [ ! -d "/home/axe/guaconfig/keymap" ]; then
        mkdir -p /home/axe/guaconfig/keymap
    fi

    # copy keymap config file
    cp "$work_path"/keymap-v2/keymap-v2.conf /home/axe/guaconfig/keymap/keymap-v2.conf
}

build_and_install() {
	cd "$work_path"/keymap-v2/x-set-keys
	make
	sudo make install
}

install_dependencies() {
	sudo apt install -y libglib2.0-dev libx11-dev gcc
}

init() {
    rm -rf "$work_path"/keymap-v2
    git clone https://gitee.com/hkmc/keymap-v2
}

__main() {
  init
	install_dependencies
	build_and_install
	config_keymap
	config_start
}

__main
